//	Project:	HexTower
//	File:		TileManager.cpp
//	Author:		Mustafa Aldoori
//	Purpose:	Tile Manager implementation, loads and runs the world compartments.

#include "TileManager.h"

CTileManager* CTileManager::GetInstance( )
{
	static CTileManager s_Instance;

	return &s_Instance;
}

CTileManager::CTileManager( void )
{

}

CTileManager::~CTileManager( void )
{

}

void CTileManager::AddTile( CTile& pTile )
{
	pTile.AddRef();
	if( ( unsigned int )pTile.GetTileX( ) >= m_vTileList.size( ) )
		m_vTileList.resize(pTile.GetTileX( ) + 1 );

	if( ( unsigned int )pTile.GetTileY( ) >= m_vTileList[ pTile.GetTileX( ) ].size( ) )
		m_vTileList[ pTile.GetTileX( ) ].resize( pTile.GetTileY( ) + 1 );

	m_vTileList[ pTile.GetTileX( ) ][ pTile.GetTileY( ) ] = &pTile;
}

void CTileManager::RemoveAllTiles( )
{

	for ( unsigned int x = 0; x < m_vTileList.size(); ++x )
	{
		for ( unsigned int y = 0; y < m_vTileList[ x ].size(); ++y ) 
		{
			if ( m_vTileList[ x ][ y ] == nullptr ) 
				continue;

			//pFM->ReleaseTexture( m_vTileList[ x ][ y ]->GetImageID() );

			CTile* temp = m_vTileList[ x ][ y ];
			delete temp;
			m_vTileList[ x ][ y ] = nullptr;
		}
	}
	m_vTileList.clear();
}

void CTileManager::Render()
{
	// Loop through and render all tiles that are specified to render

	// Grid when mouse is over certain area
}

void CTileManager::InitTileWorld()
{
	// Make a Tile World we can interact with
}
